/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2012                    */
/* Created on:     10-10-2013 15:57:20                          */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ANESTESISTAATENCION') and o.name = 'FK_ANESTESI_ANESTESIS_ATENCION')
alter table ANESTESISTAATENCION
   drop constraint FK_ANESTESI_ANESTESIS_ATENCION
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ANESTESISTAATENCION') and o.name = 'FK_ANESTESI_ANESTESIS_MEDICO')
alter table ANESTESISTAATENCION
   drop constraint FK_ANESTESI_ANESTESIS_MEDICO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ARSELANEROATENCION') and o.name = 'FK_ARSELANE_ARSELANER_ENFERMER')
alter table ARSELANEROATENCION
   drop constraint FK_ARSELANE_ARSELANER_ENFERMER
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ARSELANEROATENCION') and o.name = 'FK_ARSELANE_ARSELANER_ATENCION')
alter table ARSELANEROATENCION
   drop constraint FK_ARSELANE_ARSELANER_ATENCION
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ATENCIONMEDICA') and o.name = 'FK_ATENCION_BONOATENC_PAGO')
alter table ATENCIONMEDICA
   drop constraint FK_ATENCION_BONOATENC_PAGO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ATENCIONMEDICA') and o.name = 'FK_ATENCION_BOXDECONS_BOX')
alter table ATENCIONMEDICA
   drop constraint FK_ATENCION_BOXDECONS_BOX
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ATENCIONMEDICA') and o.name = 'FK_ATENCION_CONSULTAP_PACIENTE')
alter table ATENCIONMEDICA
   drop constraint FK_ATENCION_CONSULTAP_PACIENTE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ATENCIONMEDICA') and o.name = 'FK_ATENCION_MEDICOENC_MEDICO')
alter table ATENCIONMEDICA
   drop constraint FK_ATENCION_MEDICOENC_MEDICO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ENFERMERA') and o.name = 'FK_ENFERMER_ESENFERME_FUNCIONA')
alter table ENFERMERA
   drop constraint FK_ENFERMER_ESENFERME_FUNCIONA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ENFERMERAATENCION') and o.name = 'FK_ENFERMER_ENFERMERA_ATENCION')
alter table ENFERMERAATENCION
   drop constraint FK_ENFERMER_ENFERMERA_ATENCION
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ENFERMERAATENCION') and o.name = 'FK_ENFERMER_ENFERMERA_ENFERMER')
alter table ENFERMERAATENCION
   drop constraint FK_ENFERMER_ENFERMERA_ENFERMER
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('FUNCIONARIO') and o.name = 'FK_FUNCIONA_ESFUNCION_PERSONA')
alter table FUNCIONARIO
   drop constraint FK_FUNCIONA_ESFUNCION_PERSONA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('INSUMOS_CONSULTA') and o.name = 'FK_INSUMOS__INSUMOS_C_ATENCION')
alter table INSUMOS_CONSULTA
   drop constraint FK_INSUMOS__INSUMOS_C_ATENCION
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('INSUMOS_CONSULTA') and o.name = 'FK_INSUMOS__INSUMOS_C_INSUMO')
alter table INSUMOS_CONSULTA
   drop constraint FK_INSUMOS__INSUMOS_C_INSUMO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('MEDICO') and o.name = 'FK_MEDICO_ESMEDICO_FUNCIONA')
alter table MEDICO
   drop constraint FK_MEDICO_ESMEDICO_FUNCIONA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PACIENTE') and o.name = 'FK_PACIENTE_ESPACIENT_PERSONA')
alter table PACIENTE
   drop constraint FK_PACIENTE_ESPACIENT_PERSONA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PAGO') and o.name = 'FK_PAGO_COBROPACI_PACIENTE')
alter table PAGO
   drop constraint FK_PAGO_COBROPACI_PACIENTE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('URGENCIA') and o.name = 'FK_URGENCIA_BOXDEURGE_BOX')
alter table URGENCIA
   drop constraint FK_URGENCIA_BOXDEURGE_BOX
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('URGENCIA') and o.name = 'FK_URGENCIA_FUNCIONAR_FUNCIONA')
alter table URGENCIA
   drop constraint FK_URGENCIA_FUNCIONAR_FUNCIONA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('URGENCIA') and o.name = 'FK_URGENCIA_PACIENTEU_PACIENTE')
alter table URGENCIA
   drop constraint FK_URGENCIA_PACIENTEU_PACIENTE
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ANESTESISTAATENCION')
            and   name  = 'ANESTESISTAATENCION2_FK'
            and   indid > 0
            and   indid < 255)
   drop index ANESTESISTAATENCION.ANESTESISTAATENCION2_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ANESTESISTAATENCION')
            and   name  = 'ANESTESISTAATENCION_FK'
            and   indid > 0
            and   indid < 255)
   drop index ANESTESISTAATENCION.ANESTESISTAATENCION_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ANESTESISTAATENCION')
            and   type = 'U')
   drop table ANESTESISTAATENCION
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ARSELANEROATENCION')
            and   name  = 'ARSELANEROATENCION2_FK'
            and   indid > 0
            and   indid < 255)
   drop index ARSELANEROATENCION.ARSELANEROATENCION2_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ARSELANEROATENCION')
            and   name  = 'ARSELANEROATENCION_FK'
            and   indid > 0
            and   indid < 255)
   drop index ARSELANEROATENCION.ARSELANEROATENCION_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ARSELANEROATENCION')
            and   type = 'U')
   drop table ARSELANEROATENCION
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ATENCIONMEDICA')
            and   name  = 'BONOATENCION_FK'
            and   indid > 0
            and   indid < 255)
   drop index ATENCIONMEDICA.BONOATENCION_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ATENCIONMEDICA')
            and   name  = 'MEDICOENCARGADO_FK'
            and   indid > 0
            and   indid < 255)
   drop index ATENCIONMEDICA.MEDICOENCARGADO_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ATENCIONMEDICA')
            and   name  = 'CONSULTAPACIENTE_FK'
            and   indid > 0
            and   indid < 255)
   drop index ATENCIONMEDICA.CONSULTAPACIENTE_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ATENCIONMEDICA')
            and   name  = 'BOXDECONSULTA_FK'
            and   indid > 0
            and   indid < 255)
   drop index ATENCIONMEDICA.BOXDECONSULTA_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ATENCIONMEDICA')
            and   type = 'U')
   drop table ATENCIONMEDICA
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BOX')
            and   type = 'U')
   drop table BOX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ENFERMERA')
            and   type = 'U')
   drop table ENFERMERA
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ENFERMERAATENCION')
            and   name  = 'ENFERMERAATENCION2_FK'
            and   indid > 0
            and   indid < 255)
   drop index ENFERMERAATENCION.ENFERMERAATENCION2_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ENFERMERAATENCION')
            and   name  = 'ENFERMERAATENCION_FK'
            and   indid > 0
            and   indid < 255)
   drop index ENFERMERAATENCION.ENFERMERAATENCION_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ENFERMERAATENCION')
            and   type = 'U')
   drop table ENFERMERAATENCION
go

if exists (select 1
            from  sysobjects
           where  id = object_id('FUNCIONARIO')
            and   type = 'U')
   drop table FUNCIONARIO
go

if exists (select 1
            from  sysobjects
           where  id = object_id('INSUMO')
            and   type = 'U')
   drop table INSUMO
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('INSUMOS_CONSULTA')
            and   name  = 'INSUMOS_CONSULTA2_FK'
            and   indid > 0
            and   indid < 255)
   drop index INSUMOS_CONSULTA.INSUMOS_CONSULTA2_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('INSUMOS_CONSULTA')
            and   name  = 'INSUMOS_CONSULTA_FK'
            and   indid > 0
            and   indid < 255)
   drop index INSUMOS_CONSULTA.INSUMOS_CONSULTA_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('INSUMOS_CONSULTA')
            and   type = 'U')
   drop table INSUMOS_CONSULTA
go

if exists (select 1
            from  sysobjects
           where  id = object_id('MEDICO')
            and   type = 'U')
   drop table MEDICO
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PACIENTE')
            and   type = 'U')
   drop table PACIENTE
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PAGO')
            and   name  = 'COBROPACIENTE_FK'
            and   indid > 0
            and   indid < 255)
   drop index PAGO.COBROPACIENTE_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PAGO')
            and   type = 'U')
   drop table PAGO
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PERSONA')
            and   type = 'U')
   drop table PERSONA
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('URGENCIA')
            and   name  = 'BOXDEURGENCIA_FK'
            and   indid > 0
            and   indid < 255)
   drop index URGENCIA.BOXDEURGENCIA_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('URGENCIA')
            and   name  = 'FUNCIONARIOENCARGADO_FK'
            and   indid > 0
            and   indid < 255)
   drop index URGENCIA.FUNCIONARIOENCARGADO_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('URGENCIA')
            and   name  = 'PACIENTEURGENCIA_FK'
            and   indid > 0
            and   indid < 255)
   drop index URGENCIA.PACIENTEURGENCIA_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('URGENCIA')
            and   type = 'U')
   drop table URGENCIA
go

/*==============================================================*/
/* Table: ANESTESISTAATENCION                                   */
/*==============================================================*/
create table ANESTESISTAATENCION (
   RUN                  varchar(16)          not null,
   ID_CONSULTA          int                  not null,
   constraint PK_ANESTESISTAATENCION primary key (RUN, ID_CONSULTA)
)
go

/*==============================================================*/
/* Index: ANESTESISTAATENCION_FK                                */
/*==============================================================*/
create index ANESTESISTAATENCION_FK on ANESTESISTAATENCION (
ID_CONSULTA ASC
)
go

/*==============================================================*/
/* Index: ANESTESISTAATENCION2_FK                               */
/*==============================================================*/
create index ANESTESISTAATENCION2_FK on ANESTESISTAATENCION (
RUN ASC
)
go

/*==============================================================*/
/* Table: ARSELANEROATENCION                                    */
/*==============================================================*/
create table ARSELANEROATENCION (
   RUN                  varchar(16)          not null,
   ID_CONSULTA          int                  not null,
   constraint PK_ARSELANEROATENCION primary key (RUN, ID_CONSULTA)
)
go

/*==============================================================*/
/* Index: ARSELANEROATENCION_FK                                 */
/*==============================================================*/
create index ARSELANEROATENCION_FK on ARSELANEROATENCION (
RUN ASC
)
go

/*==============================================================*/
/* Index: ARSELANEROATENCION2_FK                                */
/*==============================================================*/
create index ARSELANEROATENCION2_FK on ARSELANEROATENCION (
ID_CONSULTA ASC
)
go

/*==============================================================*/
/* Table: ATENCIONMEDICA                                        */
/*==============================================================*/
create table ATENCIONMEDICA (
   ID_CONSULTA          int                  not null,
   BOLETA               int                  not null,
   BOX                  int                  not null,
   PACIENTE             varchar(16)          not null,
   MEDICOENCARGADO      varchar(16)          not null,
   FECHACONSULTA        datetime             not null,
   COSTO                money                not null,
   TIPOPROCEDIMIENTO    varchar(64)          null,
   constraint PK_ATENCIONMEDICA primary key nonclustered (ID_CONSULTA)
)
go

/*==============================================================*/
/* Index: BOXDECONSULTA_FK                                      */
/*==============================================================*/
create index BOXDECONSULTA_FK on ATENCIONMEDICA (
BOX ASC
)
go

/*==============================================================*/
/* Index: CONSULTAPACIENTE_FK                                   */
/*==============================================================*/
create index CONSULTAPACIENTE_FK on ATENCIONMEDICA (
PACIENTE ASC
)
go

/*==============================================================*/
/* Index: MEDICOENCARGADO_FK                                    */
/*==============================================================*/
create index MEDICOENCARGADO_FK on ATENCIONMEDICA (
MEDICOENCARGADO ASC
)
go

/*==============================================================*/
/* Index: BONOATENCION_FK                                       */
/*==============================================================*/
create index BONOATENCION_FK on ATENCIONMEDICA (
BOLETA ASC
)
go

/*==============================================================*/
/* Table: BOX                                                   */
/*==============================================================*/
create table BOX (
   NUMEROBOX            int                  not null,
   ESPECIALIDADBOX      char(32)             not null,
   BOXDISPONIBLE        bit                  not null,
   constraint PK_BOX primary key nonclustered (NUMEROBOX)
)
go

/*==============================================================*/
/* Table: ENFERMERA                                             */
/*==============================================================*/
create table ENFERMERA (
   RUN                  varchar(16)          not null,
   ESPECIALIDAD_ENFERMERIA varchar(32)          not null,
   NOMBRE               varchar(32)          not null,
   APELLIDOPATERNO      varchar(32)          not null,
   APELLIDOMATERNO      varchar(32)          not null,
   FECHANACIMIENTO      datetime             null,
   SEXO                 char(1)              not null,
   DISPONIBILIDAD_FUNCIONARIO bit                  not null,
   constraint PK_ENFERMERA primary key (RUN)
)
go

/*==============================================================*/
/* Table: ENFERMERAATENCION                                     */
/*==============================================================*/
create table ENFERMERAATENCION (
   RUN                  varchar(16)          not null,
   ID_CONSULTA          int                  not null,
   constraint PK_ENFERMERAATENCION primary key (RUN, ID_CONSULTA)
)
go

/*==============================================================*/
/* Index: ENFERMERAATENCION_FK                                  */
/*==============================================================*/
create index ENFERMERAATENCION_FK on ENFERMERAATENCION (
ID_CONSULTA ASC
)
go

/*==============================================================*/
/* Index: ENFERMERAATENCION2_FK                                 */
/*==============================================================*/
create index ENFERMERAATENCION2_FK on ENFERMERAATENCION (
RUN ASC
)
go

/*==============================================================*/
/* Table: FUNCIONARIO                                           */
/*==============================================================*/
create table FUNCIONARIO (
   RUN                  varchar(16)          not null,
   NOMBRE               varchar(32)          not null,
   APELLIDOPATERNO      varchar(32)          not null,
   APELLIDOMATERNO      varchar(32)          not null,
   FECHANACIMIENTO      datetime             null,
   SEXO                 char(1)              not null,
   DISPONIBILIDAD_FUNCIONARIO bit                  not null,
   constraint PK_FUNCIONARIO primary key (RUN)
)
go

/*==============================================================*/
/* Table: INSUMO                                                */
/*==============================================================*/
create table INSUMO (
   CODIGO_INSUMO        int                  not null,
   NOMBRE_INSUMO        varchar(64)          not null,
   PRECIO_INSUMO        money                not null,
   constraint PK_INSUMO primary key nonclustered (CODIGO_INSUMO)
)
go

/*==============================================================*/
/* Table: INSUMOS_CONSULTA                                      */
/*==============================================================*/
create table INSUMOS_CONSULTA (
   ID_CONSULTA          int                  not null,
   CODIGO_INSUMO        int                  not null,
   CANTIDAD_INSUMOSCONSULTA int                  not null,
   constraint PK_INSUMOS_CONSULTA primary key (ID_CONSULTA, CODIGO_INSUMO)
)
go

/*==============================================================*/
/* Index: INSUMOS_CONSULTA_FK                                   */
/*==============================================================*/
create index INSUMOS_CONSULTA_FK on INSUMOS_CONSULTA (
ID_CONSULTA ASC
)
go

/*==============================================================*/
/* Index: INSUMOS_CONSULTA2_FK                                  */
/*==============================================================*/
create index INSUMOS_CONSULTA2_FK on INSUMOS_CONSULTA (
CODIGO_INSUMO ASC
)
go

/*==============================================================*/
/* Table: MEDICO                                                */
/*==============================================================*/
create table MEDICO (
   RUN                  varchar(16)          not null,
   ESPECIALIDAD_MEDICO  varchar(32)          not null,
   NOMBRE               varchar(32)          not null,
   APELLIDOPATERNO      varchar(32)          not null,
   APELLIDOMATERNO      varchar(32)          not null,
   FECHANACIMIENTO      datetime             null,
   SEXO                 char(1)              not null,
   DISPONIBILIDAD_FUNCIONARIO bit                  not null,
   constraint PK_MEDICO primary key (RUN)
)
go

/*==============================================================*/
/* Table: PACIENTE                                              */
/*==============================================================*/
create table PACIENTE (
   RUN                  varchar(16)          not null,
   NOMBRE               varchar(32)          not null,
   APELLIDOPATERNO      varchar(32)          not null,
   APELLIDOMATERNO      varchar(32)          not null,
   FECHANACIMIENTO      datetime             null,
   SEXO                 char(1)              not null,
   TELEFONOPACIENTE     varchar(64)          null,
   DIRECCION_PACIENTE   varchar(256)         null,
   PREVISION_PACIENTE   varchar(32)          not null,
   constraint PK_PACIENTE primary key (RUN)
)
go

/*==============================================================*/
/* Table: PAGO                                                  */
/*==============================================================*/
create table PAGO (
   NUMEROBOLETA         int                  not null,
   RUN                  varchar(16)          not null,
   FECHAPAGO            datetime             not null,
   MONTO                money                not null,
   constraint PK_PAGO primary key nonclustered (NUMEROBOLETA)
)
go

/*==============================================================*/
/* Index: COBROPACIENTE_FK                                      */
/*==============================================================*/
create index COBROPACIENTE_FK on PAGO (
RUN ASC
)
go

/*==============================================================*/
/* Table: PERSONA                                               */
/*==============================================================*/
create table PERSONA (
   RUN                  varchar(16)          not null,
   NOMBRE               varchar(32)          not null,
   APELLIDOPATERNO      varchar(32)          not null,
   APELLIDOMATERNO      varchar(32)          not null,
   FECHANACIMIENTO      datetime             null,
   SEXO                 char(1)              not null,
   constraint PK_PERSONA primary key nonclustered (RUN)
)
go

/*==============================================================*/
/* Table: URGENCIA                                              */
/*==============================================================*/
create table URGENCIA (
   PACIENTE             varchar(16)          not null,
   ENCARGADO            varchar(16)          not null,
   ID_URGENCIA          int                  not null,
   NUMEROBOX            int                  not null,
   FECHAHORA_URGENCIA   datetime             not null,
   PRIORIDAD_URGENCIA   varchar(16)          not null,
   ESPECIALIDAD_URGENCIA varchar(32)          not null,
   DIAGNOSTICO_URGENCIA varchar(256)         not null,
   constraint PK_URGENCIA primary key nonclustered (PACIENTE, ENCARGADO, ID_URGENCIA)
)
go

/*==============================================================*/
/* Index: PACIENTEURGENCIA_FK                                   */
/*==============================================================*/
create index PACIENTEURGENCIA_FK on URGENCIA (
PACIENTE ASC
)
go

/*==============================================================*/
/* Index: FUNCIONARIOENCARGADO_FK                               */
/*==============================================================*/
create index FUNCIONARIOENCARGADO_FK on URGENCIA (
ENCARGADO ASC
)
go

/*==============================================================*/
/* Index: BOXDEURGENCIA_FK                                      */
/*==============================================================*/
create index BOXDEURGENCIA_FK on URGENCIA (
NUMEROBOX ASC
)
go

alter table ANESTESISTAATENCION
   add constraint FK_ANESTESI_ANESTESIS_ATENCION foreign key (ID_CONSULTA)
      references ATENCIONMEDICA (ID_CONSULTA)
go

alter table ANESTESISTAATENCION
   add constraint FK_ANESTESI_ANESTESIS_MEDICO foreign key (RUN)
      references MEDICO (RUN)
go

alter table ARSELANEROATENCION
   add constraint FK_ARSELANE_ARSELANER_ENFERMER foreign key (RUN)
      references ENFERMERA (RUN)
go

alter table ARSELANEROATENCION
   add constraint FK_ARSELANE_ARSELANER_ATENCION foreign key (ID_CONSULTA)
      references ATENCIONMEDICA (ID_CONSULTA)
go

alter table ATENCIONMEDICA
   add constraint FK_ATENCION_BONOATENC_PAGO foreign key (BOLETA)
      references PAGO (NUMEROBOLETA)
go

alter table ATENCIONMEDICA
   add constraint FK_ATENCION_BOXDECONS_BOX foreign key (BOX)
      references BOX (NUMEROBOX)
go

alter table ATENCIONMEDICA
   add constraint FK_ATENCION_CONSULTAP_PACIENTE foreign key (PACIENTE)
      references PACIENTE (RUN)
go

alter table ATENCIONMEDICA
   add constraint FK_ATENCION_MEDICOENC_MEDICO foreign key (MEDICOENCARGADO)
      references MEDICO (RUN)
go

alter table ENFERMERA
   add constraint FK_ENFERMER_ESENFERME_FUNCIONA foreign key (RUN)
      references FUNCIONARIO (RUN)
go

alter table ENFERMERAATENCION
   add constraint FK_ENFERMER_ENFERMERA_ATENCION foreign key (ID_CONSULTA)
      references ATENCIONMEDICA (ID_CONSULTA)
go

alter table ENFERMERAATENCION
   add constraint FK_ENFERMER_ENFERMERA_ENFERMER foreign key (RUN)
      references ENFERMERA (RUN)
go

alter table FUNCIONARIO
   add constraint FK_FUNCIONA_ESFUNCION_PERSONA foreign key (RUN)
      references PERSONA (RUN)
go

alter table INSUMOS_CONSULTA
   add constraint FK_INSUMOS__INSUMOS_C_ATENCION foreign key (ID_CONSULTA)
      references ATENCIONMEDICA (ID_CONSULTA)
go

alter table INSUMOS_CONSULTA
   add constraint FK_INSUMOS__INSUMOS_C_INSUMO foreign key (CODIGO_INSUMO)
      references INSUMO (CODIGO_INSUMO)
go

alter table MEDICO
   add constraint FK_MEDICO_ESMEDICO_FUNCIONA foreign key (RUN)
      references FUNCIONARIO (RUN)
go

alter table PACIENTE
   add constraint FK_PACIENTE_ESPACIENT_PERSONA foreign key (RUN)
      references PERSONA (RUN)
go

alter table PAGO
   add constraint FK_PAGO_COBROPACI_PACIENTE foreign key (RUN)
      references PACIENTE (RUN)
go

alter table URGENCIA
   add constraint FK_URGENCIA_BOXDEURGE_BOX foreign key (NUMEROBOX)
      references BOX (NUMEROBOX)
go

alter table URGENCIA
   add constraint FK_URGENCIA_FUNCIONAR_FUNCIONA foreign key (ENCARGADO)
      references FUNCIONARIO (RUN)
go

alter table URGENCIA
   add constraint FK_URGENCIA_PACIENTEU_PACIENTE foreign key (PACIENTE)
      references PACIENTE (RUN)
go

